*** This file creates the event study parameter datasets with the first statutory increase year as the first treatment year
*** Here we do break states up into large increaser and small categories


*** Last updated: 2/8/2024 

capture log close
set more off
set matsize 11000
* If needed change global path to point to directory where files are stored on your computer
*global path "I:/DataSets5/Duncan/Dropbox/Recent Minimum Wage Changes/2020.12 NBER Update/JOLE Precommittment Replication"

global dtadir "$path/Data"
global tabdir "$path/Tables"
global figdir "$path/Figures"
global estdir "$path/Estimates"
global logdir "$path/Logfiles"

log using "$logdir/event-studies-combine-large-small-drop-indexers.log", replace

*** Assemble relevant years of ACS 
use "${path}/Data/ACS-2019.dta", clear

*** Drop seniors
drop if age >= 65 | age < 16
drop if empstat == 0

*** Construct economic outcomes of interest 
gen employed = 0
replace employed = 1 if  empstat == 1

gen inlaborforce = 0
replace inlaborforce = 1 if  labforce == 2

gen unemployed = 0
replace unemployed = 1 if inlaborforce == 1 & employed == 0

**** Construct education variables

gen dropout = 0 
replace dropout = 1 if educ < 6
gen highschool = 0 
replace highschool = 1 if educ == 6
gen somecollege = 0
replace somecollege = 1 if educ >= 7 & educ < 10
gen collegeplus = 0
replace collegeplus = 1 if educ >= 10

***
* Assign the policy categories
***

merge m:1 statefip using "${path}/Data/min_wage_variables_for_ACS_and_CPS_analysis.dta"
drop _merge

drop statincreasebydec201*
drop statincreasebyjan20*

gen indexer = 0
replace indexer = 1 if originaltype == "Indexer"
gen StatIncreaserLarge = 0
replace StatIncreaserLarge = 1 if indexer == 0 & (jan2015min - jan2013min) >= 1 & (jan2016min - jan2013min) != .
gen statutoryincreasein2014or2015 = 0
replace statutoryincreasein2014or2015 = 1 if (jan2016min - jan2013min) > 0 & indexer == 0
gen StatIncreaserSmall = 0
replace StatIncreaserSmall = 1 if indexer == 0 & statutoryincreasein2014or2015 == 1 & StatIncreaserLarge == 0

*** Fix weight variable
rename perwt cmpwgt

gen mw_jan =. 

forval year = 2011/2019 {
	replace mw_jan = jan`year'min if year == `year'
}

forval year = 2011/2019 {
	gen mw_jan`year'B = mw_jan if year == `year'
	gegen mw_jan`year' = max(mw_jan`year'B), by(statefip)
	drop mw_jan`year'B
}

forval year = 2012/2019 {
	local j = `year' - 1
	gen mw_change`year' = mw_jan`year' - mw_jan`j' > .01
}

*** Generate total minimum wage change from 2011 - 2019
gen totalchange = mw_jan2019 - mw_jan2011

*** Generate year of first minimum wage change
gen eventyear = 0
replace eventyear = 2012 if mw_change2012 == 1
replace eventyear = 2013 if mw_change2013 == 1 & mw_change2012 == 0
replace eventyear = 2014 if mw_change2014 == 1 & mw_change2012 == 0 & mw_change2013 == 0
replace eventyear = 2015 if mw_change2015 == 1 & mw_change2012 == 0 & mw_change2013 == 0 & mw_change2014 == 0
replace eventyear = 2016 if mw_change2016 == 1 & mw_change2012 == 0 & mw_change2013 == 0 & mw_change2014 == 0 & mw_change2015 == 0
replace eventyear = 2017 if mw_change2017 == 1 & mw_change2012 == 0 & mw_change2013 == 0 & mw_change2014 == 0 & mw_change2015 == 0 & mw_change2016 == 0 
replace eventyear = 2018 if mw_change2018 == 1 & mw_change2012 == 0 & mw_change2013 == 0 & mw_change2014 == 0 & mw_change2015 == 0 & mw_change2016 == 0 & mw_change2017 == 0
replace eventyear = 2019 if mw_change2019 == 1 & mw_change2012 == 0 & mw_change2013 == 0 & mw_change2014 == 0 & mw_change2015 == 0 & mw_change2016 == 0 & mw_change2017 == 0 & mw_change2018 == 0
drop mw_change2012 mw_change2013 mw_change2014 mw_change2015 mw_change2016 mw_change2017  mw_change2018 mw_change2019


* Since New York's increase officially occurs on 12/13/2013 just set the year of first increase and year of first legislated increase to 2014
replace eventyear = 2014 if statefip == 36

* Generate time variable where the year right before the first increase is 0 and the year of first increase is 1.
gen inctime = year - eventyear + 1
replace inctime = 999 if inctime > 2010

*** Drop states that are only indexers and never changed to increasers during the sample (FL, MT, OH)
drop if statefip == 12 | statefip == 30 | statefip == 39

*** Alter event years for states that have either always been indexers or that shifted
*** from being indexers to having new statory increases.

gen eventyearNOI = eventyear
replace eventyearNOI = 0 if statefip == 12 | statefip == 30 | statefip == 39
replace eventyearNOI = 2014 if statefip == 50
replace eventyearNOI = 2016 if statefip == 41
replace eventyearNOI = 2017 if statefip == 4 | statefip == 8 |  statefip == 23 | statefip == 53
replace eventyearNOI = 2019 if statefip == 29

*** Generate year of First Increase or First Legislated Increase
gen year1 = year(date1)
gen legyear1 = year(legdate1)

* Since we don't have 2020 data yet, put the states with first increases in 2020 or first legislation passed in 2019 into the never increased category
replace year1 =. if year1 == 2020
replace legyear1 =. if legyear1 == 2019

tab year1
tab legyear1

* First increase associated with new legislation
* For most states, this will be the year after a minimum wage increase is passed
* But some states, like DE, MI, MN, and OR passed and enacted an increase in the same calendar year.
gen legimpyear1 = legyear1

replace legimpyear1 = legyear1 + 1 if legyear1 !=. & !inlist(statefip,10,26,27,41)

replace legimpyear1 = legyear1 if inlist(statefip,10,26,27,41)

* Get cohorts for each increase type
levelsof year1, local(firstincreaseyear)
levelsof legyear1, local(firstlegyear)
levelsof legimpyear1, local(legimpyear)

* Generate time variable where the year right before the first increase is 0 and the year of first increase is 1.
gen inctimeNOI = year - legimpyear + 1
replace inctimeNOI = 999 if inctimeNOI > 2010

* Check year of first increase by state
tab state legimpyear1

* Check that eventtime is coded as 1 for the year of first increase
tab state year if inctimeNOI == 1

*** Create event dummies for each policy group. Make sure Maine is added to this group since it had minimum wage increases starting in 2017
gen largeinctimeNOIneg4plus = inctimeNOI <= -4 & (StatIncreaserLarge == 1 | statefip == 23)
gen largeinctimeNOIneg3plus = inctimeNOI <= -3 & (StatIncreaserLarge == 1 | statefip == 23)
gen largeinctimeNOIneg2plus = inctimeNOI <= -2 & (StatIncreaserLarge == 1 | statefip == 23)
gen largeinctimeNOIneg3 = inctimeNOI == -3 & (StatIncreaserLarge == 1 | statefip == 23)
gen largeinctimeNOIneg2 = inctimeNOI == -2 & (StatIncreaserLarge == 1 | statefip == 23)
gen largeinctimeNOIneg1 = inctimeNOI == -1 & (StatIncreaserLarge == 1 | statefip == 23)
gen largeinctimeNOIzero = inctimeNOI == 0 & (StatIncreaserLarge == 1 | statefip == 23)
gen largeinctimeNOIpos1 = inctimeNOI == 1 & (StatIncreaserLarge == 1 | statefip == 23)
gen largeinctimeNOIpos2 = inctimeNOI == 2 & (StatIncreaserLarge == 1 | statefip == 23)
gen largeinctimeNOIpos3 = inctimeNOI == 3 & (StatIncreaserLarge == 1 | statefip == 23)
gen largeinctimeNOIpos2plus = inctimeNOI >= 2 & inctimeNOI != 999 & (StatIncreaserLarge == 1 | statefip == 23)
gen largeinctimeNOIpos3plus = inctimeNOI >= 3 & inctimeNOI != 999 & (StatIncreaserLarge == 1 | statefip == 23)
gen largeinctimeNOIpos4plus = inctimeNOI >= 4 & inctimeNOI != 999 & (StatIncreaserLarge == 1 | statefip == 23)

gen smallinctimeNOIneg4plus = inctimeNOI <= -4 & StatIncreaserSmall == 1
gen smallinctimeNOIneg3plus = inctimeNOI <= -3 & StatIncreaserSmall == 1
gen smallinctimeNOIneg2plus = inctimeNOI <= -2 & StatIncreaserSmall == 1
gen smallinctimeNOIneg3 = inctimeNOI == -3 & StatIncreaserSmall == 1
gen smallinctimeNOIneg2 = inctimeNOI == -2 & StatIncreaserSmall == 1
gen smallinctimeNOIneg1 = inctimeNOI == -1 & StatIncreaserSmall == 1
gen smallinctimeNOIzero = inctimeNOI == 0 & StatIncreaserSmall == 1
gen smallinctimeNOIpos1 = inctimeNOI == 1 & StatIncreaserSmall == 1
gen smallinctimeNOIpos2 = inctimeNOI == 2 & StatIncreaserSmall == 1
gen smallinctimeNOIpos3 = inctimeNOI == 3 & StatIncreaserSmall == 1
gen smallinctimeNOIpos2plus = inctimeNOI >= 2 & inctimeNOI != 999 & StatIncreaserSmall == 1
gen smallinctimeNOIpos3plus = inctimeNOI >= 3 & inctimeNOI != 999 & StatIncreaserSmall == 1
gen smallinctimeNOIpos4plus = inctimeNOI >= 4 & inctimeNOI != 999 & StatIncreaserSmall == 1

gen indexinctimeNOIneg4plus = inctimeNOI <= -4 & indexer == 1
gen indexinctimeNOIneg3plus = inctimeNOI <= -3 & indexer == 1
gen indexinctimeNOIneg2plus = inctimeNOI <= -2 & indexer == 1
gen indexinctimeNOIneg3 = inctimeNOI == -3 & indexer == 1
gen indexinctimeNOIneg2 = inctimeNOI == -2 & indexer == 1
gen indexinctimeNOIneg1 = inctimeNOI == -1 & indexer == 1
gen indexinctimeNOIzero = inctimeNOI == 0 & indexer == 1
gen indexinctimeNOIpos1 = inctimeNOI == 1 & indexer == 1
gen indexinctimeNOIpos2 = inctimeNOI == 2 & indexer == 1
gen indexinctimeNOIpos3 = inctimeNOI == 3 & indexer == 1
gen indexinctimeNOIpos2plus = inctimeNOI >= 2 & inctimeNOI != 999 & indexer == 1
gen indexinctimeNOIpos3plus = inctimeNOI >= 3 & inctimeNOI != 999 & indexer == 1
gen indexinctimeNOIpos4plus = inctimeNOI >= 4 & inctimeNOI != 999 & indexer == 1

gen indsminctimeNOIneg4plus = inctimeNOI <= -4 & (StatIncreaserSmall == 1 | indexer == 1)
gen indsminctimeNOIneg3plus = inctimeNOI <= -3 & (StatIncreaserSmall == 1 | indexer == 1)
gen indsminctimeNOIneg2plus = inctimeNOI <= -2 & (StatIncreaserSmall == 1 | indexer == 1)
gen indsminctimeNOIneg3 = inctimeNOI == -3 & (StatIncreaserSmall == 1 | indexer == 1)
gen indsminctimeNOIneg2 = inctimeNOI == -2 & (StatIncreaserSmall == 1 | indexer == 1)
gen indsminctimeNOIneg1 = inctimeNOI == -1 & (StatIncreaserSmall == 1 | indexer == 1)
gen indsminctimeNOIzero = inctimeNOI == 0 & (StatIncreaserSmall == 1 | indexer == 1)
gen indsminctimeNOIpos1 = inctimeNOI == 1 & (StatIncreaserSmall == 1 | indexer == 1)
gen indsminctimeNOIpos2 = inctimeNOI == 2 & (StatIncreaserSmall == 1 | indexer == 1)
gen indsminctimeNOIpos3 = inctimeNOI == 3 & (StatIncreaserSmall == 1 | indexer == 1)
gen indsminctimeNOIpos2plus = inctimeNOI >= 2 & inctimeNOI != 999 & (StatIncreaserSmall == 1 | indexer == 1)
gen indsminctimeNOIpos3plus = inctimeNOI >= 3 & inctimeNOI != 999 & (StatIncreaserSmall == 1 | indexer == 1)
gen indsminctimeNOIpos4plus = inctimeNOI >= 4 & inctimeNOI != 999 & (StatIncreaserSmall == 1 | indexer == 1)

* Generate policy group indicators
gen policygroup = 0
replace policygroup = 1 if indexer == 1
replace policygroup = 2 if StatIncreaserSmall == 1
replace policygroup = 3 if StatIncreaserLarge == 1

label define grouplbl 0 "No Change"  1 "Index" 2 "Small" 3 "Large"
label values policygroup grouplbl

* Generate alternate policy group indicators combinning small + indexer
gen policygroupalt = 0
replace policygroupalt = 1 if (StatIncreaserSmall == 1 | indexer == 1)
replace policygroupalt = 2 if StatIncreaserLarge == 1

label define altgrouplbl 0 "No Change"  1 "Index & Small" 2 "Large"
label values policygroup altgrouplbl

*** Housing Index and Income Changes
merge m:1 statefip year using "${path}/Data/HousingIndexChanges.dta"
keep if _merge == 3
drop _merge
merge m:1 statefip year using "${path}/Data/PersonalIncomeChanges.dta"
keep if _merge == 3
drop _merge

capture drop sample serial hhwt pernum cluster metro met2013 strata gq sex race raced empstat ///
empstatd labforce occ1990 ind1990 wkswork2 uhrswork inctot incwage migrate1 ///
migrate1d migplac1 movedin hcovany hinsemp hinspur hcovpub hinscaid hinscare ///
D4HPI D4lnPersonalIncome stateempD jan*min change* mw_jan* mw_change*

* Drop all indexer states
drop if indexer == 1

compress

local large largeinctimeNOIneg3plus largeinctimeNOIneg2 largeinctimeNOIneg1 largeinctimeNOIpos1 largeinctimeNOIpos2 largeinctimeNOIpos3 largeinctimeNOIpos4plus
local small smallinctimeNOIneg3plus smallinctimeNOIneg2 smallinctimeNOIneg1 smallinctimeNOIpos1 smallinctimeNOIpos2 smallinctimeNOIpos3 smallinctimeNOIpos4plus
local index indexinctimeNOIneg3plus indexinctimeNOIneg2 indexinctimeNOIneg1 indexinctimeNOIpos1 indexinctimeNOIpos2 indexinctimeNOIpos3 indexinctimeNOIpos4plus

local indexsmall indsminctimeNOIneg3plus indsminctimeNOIneg2 indsminctimeNOIneg1 indsminctimeNOIpos1 indsminctimeNOIpos2 indsminctimeNOIpos3 indsminctimeNOIpos4plus

local eventtime inctimeNOIneg3plus inctimeNOIneg2 inctimeNOIneg1 inctimeNOIpos1 inctimeNOIpos2 inctimeNOIpos3 inctimeNOIpos4plus



*** Analyses of the Low-Skill and Young Groups with varying degrees of control for house prices, income, and past changes in house prices and income


* No controls low-skilled
reghdfe employed `large' `small' [aw = cmpwgt] if age <= 25 & dropout == 1 & (year >= 2010), absorb(statefip year) cluster(statefip)
parmest,format(estimate min95 max95 %8.3f p %8.1e) saving("$estdir/EventTimePolicyCategories/EventTimeRegressionEmploymentLeastNoControls.dta", replace)

* No controls young
reghdfe employed `large' `small' [aw = cmpwgt] if age <= 21 & (year >= 2010), absorb(statefip year) cluster(statefip)
parmest,format(estimate min95 max95 %8.3f p %8.1e) saving("$estdir/EventTimePolicyCategories/EventTimeRegressionEmploymentYoungNoControls.dta", replace)

* Sparse controls low-skilled
reghdfe employed `large' `small'  lnPersonalIncome HPI [aw = cmpwgt] if age <= 25 & dropout == 1 & (year >= 2010), absorb(statefip year) cluster(statefip)
parmest,format(estimate min95 max95 %8.3f p %8.1e) saving("$estdir/EventTimePolicyCategories/EventTimeRegressionEmploymentLeastBaseControls.dta", replace)

* Sparse controls young
reghdfe employed `large' `small' lnPersonalIncome HPI  [aw = cmpwgt] if age <= 21 & (year >= 2010), absorb(statefip year) cluster(statefip)
parmest,format(estimate min95 max95 %8.3f p %8.1e) saving("$estdir/EventTimePolicyCategories/EventTimeRegressionEmploymentYoungBaseControls.dta", replace)

* Rich controls low-skilled
reghdfe employed `large' `small' D3lnPersonalIncome D3HPI  lnPersonalIncome HPI [aw = cmpwgt] if age <= 25 & dropout == 1 & (year >= 2010), absorb(statefip age educ year) cluster(statefip)
parmest,format(estimate min95 max95 %8.3f p %8.1e) saving("$estdir/EventTimePolicyCategories/EventTimeRegressionEmploymentLeastRichControls.dta", replace)

* Rich controls young
reghdfe employed `large' `small' D3lnPersonalIncome D3HPI lnPersonalIncome HPI [aw = cmpwgt] if age <= 21 & (year >= 2010), absorb(statefip age educ year) cluster(statefip)
parmest,format(estimate min95 max95 %8.3f p %8.1e) saving("$estdir/EventTimePolicyCategories/EventTimeRegressionEmploymentYoungRichControls.dta", replace)

log close
